package hxy.bytecode.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class SocketDemo {
    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        String serverIP = "127.0.0.1";    //服务器端ip地址
        int port = 8999;    //服务器端端口号
        try {
            socket = new Socket(serverIP, port);
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            out = new PrintWriter(socket.getOutputStream(), true);
//            while (true) {
                int number = (int) (Math.random() * 10) + 1;


                String msg = "{\n" +
                        "  \"action\": \"report\",\n" +
                        "  \"data\": {\n" +
                        "    \"project_id\": 1, // 项目id\n" +
                        "    \"log_category\": \"Api/PayBase/v2\", // 日志类型\n" +
                        "    \"log_point\": \"curl_begin\", // 日志记录点 (比如数据提交前)\n" +
                        "    \"log_sn\": \"666\", // 日志单号 后续可以根据订单号筛选\n" +
                        "    \"log_data\": \"{\\\"name\\\":\\\"siam\\\",\\\"age\\\":22}\", // 日志内容，可以普通字符串或者json字符串\n" +
                        "    \"log_from\": \"siam\", // 日志来自哪个平台\n" +
                        "  }\n" +
                        "}";


                System.out.println("客户端正在发送的内容为：" + msg);
                out.println(msg);
                out.flush();
                out.close();
                socket.close();
//                out.println(number);
//                Thread.sleep(2000);
//            }
        } catch (IOException  e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }
}